<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>for循环打印金字塔</title>
    <style>
        body{
            font-family: fantasy;
        }
    </style>
</head>
<body>

<script>
    /*
    //等于1，小于等于5的
    var num = prompt("请输入金字塔层数");
    for (var y = 1;y <= num;y++){
        var a = num - y;
        for (i = 1;i <= a;i++){
            document.write("&nbsp");
        }
        var h = y * 2 -1;
        for (var l = 1;l <= h;l++){
            document.write("*");
        }
        document.write("<br>");
    }
    */


    //等于0，小于5的
    var num = prompt("请输入金字塔的层数");
    for (var i = 0;i < num;i++){
        var w = num - i;
        for (var a = 0;a < w;a++){
            document.write("&nbsp");
        }
        var v = (i+1)*2-1
        for (var b = 0;b < v;b++){
            document.write("*")
        }
        document.write("<br>");
    }
</script>
</body>
</html>